<template>
  <div class="menu-box">
    <div
      class="menu"
      v-for="(menu, i) in menuList"
      :key="i"
      @click="gotoDetail(menu.statistic.sid)"
      @mouseenter="operate('enter', i)"
      @mouseleave="operate('leave', i)"
    >
      <div class="img">
        <div class="icon" v-show="menu.isShow">
          <n-icon>
            <PlayCircleTwotone />
          </n-icon>
        </div>
        <img :src="menu.cover.replace(/^([a-zA-Z]+:\/\/)?/, 'https://')" />
      </div>
      <div class="title">{{ menu.title }}</div>
    </div>
    <div class="pager" v-if="pageConfig.total < 20 ? false : true">
      <n-pagination v-model:page="pageConfig.currentPage" v-model:page-size="pageConfig.pageSize" />
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue';
import { PlayCircleTwotone } from '@vicons/antd';
import { useRouter } from 'vue-router';

const router = useRouter();

const menuList = ref([]);
const pageConfig = reactive({
  currentPage: 1,
  pageSize: 20,
  total: 0,
});

onMounted(() => {
  getMenuList();
});

async function getMenuList() {
  const res = await window.BiliAPI.searchMenu(pageConfig.currentPage);
  pageConfig.total = res.pageSize;
  menuList.value = res.data.map((item) => {
    return { isShow: false, ...item };
  });
}

function gotoDetail(sid) {
  router.push({ name: 'SongMenuPage', query: { sid } });
}

function operate(operation, i) {
  switch (operation) {
    case 'enter':
      menuList.value[i].isShow = true;
      break;
    case 'leave':
      menuList.value[i].isShow = false;
      break;
  }
}
</script>

<style lang="scss" scoped>
.menu-box {
  display: flex;
  flex-wrap: wrap;
  overflow: auto;
  height: calc(100vh - 200px);
  padding-bottom: 120px;
  .menu {
    /* 977 */
    width: 22%;
    margin: 15px 10px;
    .img {
      position: relative;
      .icon {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        backdrop-filter: blur(10px);
        font-size: 40px;
        color: #ffffff;
        z-index: 99;
        &:hover {
          color: #cfcfcf;
        }
      }
      img {
        width: 100%;
        height: auto;
        object-fit: cover;
        border-radius: 10px;
        transition: transform 0.1s linear;
        &:hover {
          transform: translateY(-15px);
          box-shadow: 20px 20px 26px #e3e3e3, -20px -20px 26px #ffffff;
        }
      }
    }
    .title {
      font-size: 16px;
      font-weight: 700;
      &:hover {
        color: #4fa2fc;
      }
    }
  }
  .pager {
    float: right;
    margin-right: 50px;
    margin-top: 50px;
  }
}
</style>
